//处理操作日志时间
const friendlyDates = (timestamp: any) => {
    var now = new Date(timestamp);
    var year = now.getFullYear(); //年 
    // 获取完整的年份(4位,1970-至今) date.getYear(); 获取当前年份(2位)
    var month = now.getMonth() + 1; //月
    var day = now.getDay(); //日
    var hour = now.getHours(); //时
    var minute = now.getMinutes(); //分
    var second = now.getSeconds(); //秒
    var millisecond = now.getMilliseconds(); //毫秒


    const dateTime = (new Date().getTime() - timestamp) / 1000//现在的时间差 毫秒/1000为秒数
    if (dateTime < 30) {
        return '刚刚'
    } else if (dateTime / 60 < 60) {
        return Math.round(dateTime / 60) + '分钟以前'//每分钟60秒
    } else if (dateTime / 60 / 60 < 24) {
        return Math.round(dateTime / 60 / 60) + '小时以前'
    } else if (dateTime < 172800) {
        return (dateTime / 86400).toFixed(0) + "天前"
    } else {
        return `${year}年${month}月${day}日${hour}时${minute}分 `
    }
}
//处理优惠劵时间
const couponDates = (timestamp: number) => {
    var now = new Date(timestamp);
    var year = now.getFullYear(); //年 
    // 获取完整的年份(4位,1970-至今) date.getYear(); 获取当前年份(2位)
    var month = (now.getMonth() + 1 + "").padStart(2, '0'); //月
    var day = (now.getDay() + "").padStart(2, '0'); //日
    var hour = (now.getHours() + "").padStart(2, '0'); //时
    var minute = (now.getMinutes() + "").padStart(2, '0'); //分
    var second = (now.getSeconds() + "").padStart(2, '0'); //秒
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`
}

export { friendlyDates, couponDates }